<?php

namespace App\Admin\Controllers;

use App\Models\Notice;
use App\Models\Crousesheet;
use App\Models\Student;
use App\Models\Squad;
use App\Models\Dictation_config;
use App\Models\Attendance_record;
use App\Models\Test_score_record;
use App\Models\Dictation_score_record;
use App\Models\Jiaxiao_record;
use App\Models\Zuoye_record;
use App\Models\Study_jindu_record;
use Encore\Admin\Auth\Database\Administrator;
use Encore\Admin\Auth\Database\Role;
use App\Admin\Extensions\Tools\IgnoreNotice;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Widgets\Box;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use Illuminate\Http\Request;
use App\Admin\Extensions\ExcelExpoter;
use Maatwebsite\Excel\Facades\Excel;
use Encore\Admin\Controllers\HasResourceActions;
use DB;

class My_todo_noticesController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index(Content $content)
    {
        return $content->header(trans('admin.my_todo_notices'))
            ->description(trans('admin.list'))
            ->body($this->grid());
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id,Content $content)
    {

    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {

    }

    public function show($id, Content $content)
    {
        $notice_type = Notice::where('id',$id)->value('notice_type');
        //dd($notice_type);
        switch ($notice_type) {
            case '1':
                //如果原来已自动生成了对应的记录，则直接显示，如果没有，则自动生成数据
                $attendance_record_num = Attendance_record::where('notice_id',$id)->count();
                if ($attendance_record_num =='0') {
                    //$crousesheet_id = Notice::where('id',$id)->value('crousesheet_id');
                    $squad_id = Notice::where('id',$id)->value('squad_id');
                    $student_ids = Student::where('squad_id',$squad_id)->where('status','1')->pluck('id')->toArray();
                    //dd(count($student_ids));
                    $data = [];
                    for ($i=0; $i <count($student_ids) ; $i++) {
                        $data[] = [
                            'notice_id' =>$id,
                            'student_id' =>$student_ids[$i],
                            'attendance_status' =>'1',
                            'created_at' => date('Y-m-d H:i:s')
                        ];
                    }
                    $res = Attendance_record::insert($data);
                    //自动生成记录后，改变对应的Notice的操作时间，并根据操作时间与截止日期比较更新状态。
                    if ($res) {
                        $notice = Notice::find($id);
                        //dd($notice);
                        $notice->operatetime = date('Y-m-d H:i:s');
                        if ($notice->operatetime<$notice->endtime&&$notice->status == '1') {
                            $notice->status = '2';
                        }

                        elseif($notice->operatetime>$notice->endtime&&$notice->status == '3') {
                            $notice->status = '4';
                        }
                        $notice->save();
                    }
                }
                break;
            case '2':
                //如果原来已自动生成了对应的记录，则直接显示，如果没有，则自动生成数据
                $test_score_record_num = Test_score_record::where('notice_id',$id)->count();
                if ($test_score_record_num =='0') {
                    $test_assign_id = Notice::where('id',$id)->value('test_assign_id');
                    $squad_id = DB::table('test_assigns')->where('id',$test_assign_id)->value('squad_id');
                    $student_ids = Student::where('squad_id',$squad_id)->where('status','1')->pluck('id')->toArray();
                    $data = [];
                    for ($i=0; $i <count($student_ids) ; $i++) {
                        $data[] = [
                            'notice_id' =>$id,
                            'student_id' =>$student_ids[$i],
                            'test_status' =>'1',
                            // 'test_score' =>'',
                            'created_at' => date('Y-m-d H:i:s')
                        ];
                    }
                    $res = Test_score_record::insert($data);
                    //自动生成记录后，改变对应的Notice的操作时间，并根据操作时间与截止日期比较更新状态。
                    if ($res) {
                        $notice = Notice::find($id);
                        //dd($notice);
                        $notice->operatetime = date('Y-m-d H:i:s');
                        if ($notice->operatetime<$notice->endtime&&$notice->status == '1') {
                            $notice->status = '2';
                        }
                        // elseif($notice->operatetime>$notice->endtime&&$notice->status == '1')
                        // {
                        //     $notice->status = '3';
                        // }
                        elseif($notice->operatetime>$notice->endtime&&$notice->status == '3') {
                            $notice->status = '4';
                        }
                        $notice->save();
                    }
                }
                break;
            case '3':
                //如果原来已自动生成了对应的记录，则直接显示，如果没有，则自动生成数据
                $jiaxiao_record_num = Jiaxiao_record::where('notice_id',$id)->count();
                if ($jiaxiao_record_num =='0') {
                    $squad_id = Notice::where('id',$id)->value('squad_id');
                    $student_ids = Student::where('squad_id',$squad_id)->where('status','1')->pluck('id')->toArray();
                    $data = [];
                    for ($i=0; $i <count($student_ids) ; $i++) {
                        $data[] = [
                            'notice_id' =>$id,
                            'student_id' =>$student_ids[$i],
                            'jiaxiao_status' =>'1',
                            // 'jiaxiao_score' =>'',
                            'created_at' => date('Y-m-d H:i:s')
                        ];
                    }
                    $res = Jiaxiao_record::insert($data);
                    //自动生成记录后，改变对应的Notice的操作时间，并根据操作时间与截止日期比较更新状态。
                    if ($res) {
                        $notice = Notice::find($id);
                        //dd($notice);
                        $notice->operatetime = date('Y-m-d H:i:s');
                        if ($notice->operatetime<$notice->endtime&&$notice->status == '1') {
                            $notice->status = '2';
                        }
                        // elseif($notice->operatetime>$notice->endtime&&$notice->status == '1')
                        // {
                        //     $notice->status = '3';
                        // }
                        elseif($notice->operatetime>$notice->endtime&&$notice->status == '3') {
                            $notice->status = '4';
                        }
                        $notice->save();
                    }
                }
                break;
            case '4':
                //如果原来已自动生成了对应的记录，则直接显示，如果没有，则自动生成数据
                $dictation_score_record_num = Dictation_score_record::where('notice_id',$id)->count();
                if ($dictation_score_record_num =='0') {
                    $dictation_config_id = Notice::where('id',$id)->value('dictation_config_id');
                    //$crousesheet_id = Dictation_config::where('id',$dictation_config_id)->value('crousesheet_id');
                    //$squad_id = Crousesheet::where('id',$crousesheet_id)->value('squads_id');
                    $squad_id = Notice::where('id',$id)->value('squad_id');
                    $student_ids = Student::where('squad_id',$squad_id)->where('status','1')->pluck('id')->toArray();
                    $data = [];
                    for ($i=0; $i <count($student_ids) ; $i++) {
                        $data[] = [
                            'notice_id' =>$id,
                            'student_id' =>$student_ids[$i],
                            'dictation_status' =>'1',
                            // 'dictation_score' =>'',
                            'created_at' => date('Y-m-d H:i:s')
                        ];
                    }
                    $res = Dictation_score_record::insert($data);
                    //自动生成记录后，改变对应的Notice的操作时间，并根据操作时间与截止日期比较更新状态。
                    if ($res) {
                        $notice = Notice::find($id);
                        $notice->operatetime = date('Y-m-d H:i:s');
                        if ($notice->operatetime<$notice->endtime&&$notice->status == '1') {
                            $notice->status = '2';
                        }
                        // elseif($notice->operatetime>$notice->endtime&&$notice->status == '1')
                        // {
                        //     $notice->status = '3';
                        // }
                        elseif($notice->operatetime>$notice->endtime&&$notice->status == '3') {
                            $notice->status = '4';
                        }
                        $notice->save();
                    }
                }
                break;
            case '5':
                //如果原来已自动生成了对应的记录，则直接显示，如果没有，则自动生成数据
                $zuoye_record_num = Zuoye_record::where('notice_id',$id)->count();
                if ($zuoye_record_num =='0') {
                    $squad_id = Notice::where('id',$id)->value('squad_id');
                    $student_ids = Student::where('squad_id',$squad_id)->where('status','1')->pluck('id')->toArray();
                    $data = [];
                    for ($i=0; $i <count($student_ids) ; $i++) {
                        $data[] = [
                            'notice_id' =>$id,
                            'student_id' =>$student_ids[$i],
                            'zuoye_status' =>'1',
                            // 'zuoye_score' =>'',
                            'created_at' => date('Y-m-d H:i:s')
                        ];
                    }
                    $res = Zuoye_record::insert($data);
                    //自动生成记录后，改变对应的Notice的操作时间，并根据操作时间与截止日期比较更新状态。
                    if ($res) {
                        $notice = Notice::find($id);
                        //dd($notice);
                        $notice->operatetime = date('Y-m-d H:i:s');
                        if ($notice->operatetime<$notice->endtime&&$notice->status == '1') {
                            $notice->status = '2';
                        }
                        elseif($notice->operatetime>$notice->endtime&&$notice->status == '3') {
                            $notice->status = '4';
                        }
                        $notice->save();
                    }
                }
                break;
            case '6':
                $study_jindu_record_num = Study_jindu_record::where('notice_id',$id)->count();
                if ($study_jindu_record_num == '0') {
                    return redirect('/admin/study_jindu_confirm_form/'.$id);
                }

                break;
            case '33':
                //如果原来已自动生成了对应的记录，则直接显示，如果没有，则自动生成数据
                $jiaxiao_record_num = Jiaxiao_record::where('notice_id',$id)->count();
                if ($jiaxiao_record_num =='0') {
                    $crousesheet_id = Notice::where('id',$id)->value('crousesheet_id');
                    $squad_id = Crousesheet::where('id',$crousesheet_id)->value('squads_id');
                    $student_ids = Student::where('squad_id',$squad_id)->where('status','1')->pluck('id')->toArray();
                    $data = [];
                    for ($i=0; $i <count($student_ids) ; $i++) {
                        $data[] = [
                            'notice_id' =>$id,
                            'student_id' =>$student_ids[$i],
                            'jiaxiao_status' =>'1',
                            // 'jiaxiao_score' =>'',
                            'created_at' => date('Y-m-d H:i:s')
                        ];
                    }
                    $res = Jiaxiao_record::insert($data);
                    //自动生成记录后，改变对应的Notice的操作时间，并根据操作时间与截止日期比较更新状态。
                    if ($res) {
                        $notice = Notice::find($id);
                        //dd($notice);
                        $notice->operatetime = date('Y-m-d H:i:s');
                        if ($notice->operatetime<$notice->endtime&&$notice->status == '1') {
                            $notice->status = '2';
                        }
                        // elseif($notice->operatetime>$notice->endtime&&$notice->status == '1')
                        // {
                        //     $notice->status = '3';
                        // }
                        elseif($notice->operatetime>$notice->endtime&&$notice->status == '3') {
                            $notice->status = '4';
                        }
                        $notice->save();
                    }
                }
                break;
            case '55':
                //如果原来已自动生成了对应的记录，则直接显示，如果没有，则自动生成数据
                $zuoye_record_num = Zuoye_record::where('notice_id',$id)->count();
                if ($zuoye_record_num =='0') {
                    $crousesheet_id = Notice::where('id',$id)->value('crousesheet_id');
                    $squad_id = Crousesheet::where('id',$crousesheet_id)->value('squads_id');
                    $student_ids = Student::where('squad_id',$squad_id)->where('status','1')->pluck('id')->toArray();
                    $data = [];
                    for ($i=0; $i <count($student_ids) ; $i++) {
                        $data[] = [
                            'notice_id' =>$id,
                            'student_id' =>$student_ids[$i],
                            'zuoye_status' =>'1',
                            // 'zuoye_score' =>'',
                            'created_at' => date('Y-m-d H:i:s')
                        ];
                    }
                    $res = Zuoye_record::insert($data);
                    //自动生成记录后，改变对应的Notice的操作时间，并根据操作时间与截止日期比较更新状态。
                    if ($res) {
                        $notice = Notice::find($id);
                        //dd($notice);
                        $notice->operatetime = date('Y-m-d H:i:s');
                        if ($notice->operatetime<$notice->endtime&&$notice->status == '1') {
                            $notice->status = '2';
                        }
                        elseif($notice->operatetime>$notice->endtime&&$notice->status == '3') {
                            $notice->status = '4';
                        }
                        $notice->save();
                    }
                }
                break;
            default:
                # code...
                break;
        }

        $html = $content
            ->header('事项')
            ->description(trans('admin.detail'))
            ->body(Admin::show(Notice::findOrFail($id), function (Show $show) {
                $show->panel()->tools(function ($tools){
                    $tools->disableDelete();
                    $tools->disableEdit();
                    $tools->disableList();
                });
                $show->id('ID');
                $show->event('事项内容');
                $show->starttime(trans('admin.notice_starttime'));
                $show->endtime(trans('admin.notice_endtime'));

                //不同类型的事项，显示不同的处理
                $notice_id = $show->getModel()->id;
                $notice_type2 = Notice::where('id',$notice_id)->value('notice_type');
                switch ($notice_type2) {
                    case '1':
                        $show->attendance_record('考勤记录', function ($line) {
                            $line->setResource('/admin/attendance_record');
                            //$line->model()->orderBy('id', 'desc');
                            $line->id('序号')->sortable();
                            $line->student_id(trans('admin.en_name'))->display(function($student_id){
                                return Student::find($this->student_id)->en_name;
                            });
                            $line->column(trans('admin.ch_name'))->display(function($student_id){
                                return Student::find($this->student_id)->ch_name;
                            });
                            $line->attendance_status(trans('admin.attendance_status'))->radio([
                                1 => '正常',
                                2 => '请假',
                                3 => '迟到',
                                4 => '缺勤',
                                5 => '家长代课',
                            ]);
                            $line->attendance_desc(trans('admin.attendance_desc'))->display(function($attendance_desc) {
                                    return str_limit($attendance_desc, 30, '...');
                            })->editable('textarea');
                            $line->paginate(50);
                            $line->disableActions();
                            $line->disableCreateButton();
                            $line->disableFilter();
                            $line->tools(function ($tools) {
                                $tools->batch(function ($batch) {
                                    $batch->disableDelete();
                                });
                            });
                        });
                        break;
                    case '2':
                        $show->test_score_record('成绩记录', function ($line) {
                            $line->setResource('/admin/test_score_record');
                            //$line->model()->orderBy('id', 'desc');
                            $line->id(trans('admin.ID'))->sortable();
                            $line->student_id(trans('admin.en_name'))->display(function($student_id){
                                return Student::find($this->student_id)->en_name;
                            });
                            $line->column(trans('admin.ch_name'))->display(function($student_id){
                                return Student::find($this->student_id)->ch_name;
                            });
                            $line->test_status(trans('admin.test_status'))->radio([
                                1 => '参加',
                                2 => '未参加',
                            ]);
                            //$line->test_score(trans('admin.test_score'))->editable();
                            $line->column('测试成绩')->display(function(){
                                $html = '<div class="form-inline">';
                                $html .= '<input type="text" id="'.$this->id.'-score" class="form-control score" value="'.$this->test_score.'"/>';

                                $event =  DB::table('notices as n')->join('test_assigns as ta','ta.id','=','n.test_assign_id')
                                    ->join('test_configs as tc','tc.id','=','ta.test_config_id')
                                    ->where('n.id',$this->notice_id)
                                    ->select('n.id','tc.total_score')->get();
                                $event = json_decode(json_encode($event),true);


                                $str = "'test'";
                                $html .= '<a href="###" class="editable" style="margin-left:12px" onclick="save('.$this->id.','.$str.','.$event[0]['total_score'].')"><i class="glyphicon glyphicon-ok"></i></a></div>';
                                return $html;
                            });
                            $line->test_desc(trans('admin.test_desc'))->display(function($test_desc) {
                                    return str_limit($test_desc, 30, '...');
                            })->editable('textarea');
                            $line->paginate(50);
                            $line->disableActions();
                            $line->disableCreateButton();
                            $line->disableFilter();
                            $line->tools(function ($tools) {
                                $tools->batch(function ($batch) {
                                    $batch->disableDelete();
                                });
                            });
                        });
                        break;
                    case '3':
                        $show->jiaxiao_record('家校记录', function ($line) {
                            $line->setResource('/admin/jiaxiao_record');
                            //$line->model()->orderBy('id', 'desc');
                            $line->id('序号')->sortable();
                            $line->student_id(trans('admin.en_name'))->display(function($student_id){
                                return Student::find($this->student_id)->en_name;
                            });
                            $line->column(trans('admin.ch_name'))->display(function($student_id){
                                return Student::find($this->student_id)->ch_name;
                            });
                            $line->jiaxiao_status(trans('admin.jiaxiao_status'))->radio([
                                1 => '准交',
                                2 => '未交',
                                3 => '补交'
                            ]);
                            //$line->jiaxiao_status(trans('admin.jiaxiao_status'))->editable('select', [1 => '准交', 2 => '未交',3 => '补交']);
                            $line->jiaxiao_score(trans('admin.jiaxiao_score'))->editable();
                            $line->jiaxiao_desc(trans('admin.jiaxiao_desc'))->display(function($jiaxiao_desc) {
                                    return str_limit($jiaxiao_desc, 30, '...');
                            })->editable('textarea');
                            $line->paginate(50);
                            $line->disableActions();
                            $line->disableCreateButton();
                            $line->disableFilter();
                            $line->tools(function ($tools) {
                                $tools->batch(function ($batch) {
                                    $batch->disableDelete();
                                });
                            });
                        });
                        break;
                    case '4':
                        $show->dictation_score_record('听写成绩记录', function ($line) {
                            $line->setResource('/admin/dictation_score_record');
                            //$line->model()->orderBy('id', 'desc');
                            $line->id(trans('admin.ID'))->sortable();
                            $line->student_id(trans('admin.en_name'))->display(function($student_id){
                                return Student::find($this->student_id)->en_name;
                            });
                            $line->column(trans('admin.ch_name'))->display(function($student_id){
                                return Student::find($this->student_id)->ch_name;
                            });
                            $line->dictation_status(trans('admin.dictation_status'))->radio([
                                1 => '正常',
                                2 => '未参加'
                            ]);
                            //$line->dictation_status(trans('admin.dictation_status'))->editable('select', [1 => '正常', 2 => '未参加']);
                            $line->dictation_score(trans('admin.dictation_score'))->editable();
                            $line->dictation_desc(trans('admin.dictation_desc'))->display(function($dictation_desc) {
                                    return str_limit($dictation_desc, 30, '...');
                            })->editable('textarea');
                            $line->paginate(50);
                            $line->disableActions();
                            $line->disableCreateButton();
                            $line->disableFilter();
                            $line->tools(function ($tools) {
                                $tools->batch(function ($batch) {
                                    $batch->disableDelete();
                                });
                            });
                        });
                        break;
                    case '5':
                        $show->zuoye_record('作业记录', function ($line) {
                            $line->setResource('/admin/zuoye_record');
                            //$line->model()->orderBy('id', 'desc');
                            $line->id('序号')->sortable();
                            $line->student_id(trans('admin.en_name'))->display(function($student_id){
                                return Student::find($this->student_id)->en_name;
                            });
                            $line->column(trans('admin.ch_name'))->display(function($student_id){
                                return Student::find($this->student_id)->ch_name;
                            });
                            $line->zuoye_status(trans('admin.zuoye_status'))->radio([
                                1 => '准交',
                                2 => '未交',
                                3 => '补交',
                            ]);
                            //$line->zuoye_status(trans('admin.zuoye_status'))->editable('select', ['1' => '准交', '2' => '未交',3 => '补交']);
                            $line->zuoye_score(trans('admin.zuoye_score'))->editable();
                            $line->zuoye_desc(trans('admin.zuoye_desc'))->display(function($zuoye_desc) {
                                    return str_limit($zuoye_desc, 30, '...');
                            })->editable('textarea');
                            $line->paginate(50);
                            $line->disableActions();
                            $line->disableCreateButton();
                            $line->disableFilter();
                            $line->tools(function ($tools) {
                                $tools->batch(function ($batch) {
                                    $batch->disableDelete();
                                });
                            });
                        });
                        break;
                    case '6':
                        break;
                    default:
                        # code...
                        break;
                }
            }));
        Admin::script($this->script());
            if($notice_type == "6"){
                $jindu_content = DB::table("study_jindu_records")->where([
                        "notice_id" => $id
                    ])->orderBy("id","desc")->value("jindu_content");
                $jindu_content = json_decode($jindu_content,true);
				if(!$jindu_content){
					$jindu_content = '{"teaching":[{"title":null,"book":null,"chapter":null,"desc":null,"other_zhishi_title":null,"other_zhishi_id":null}],"reading":[{"title":"绘本","chapters":null},{"title":"A to Z","atoz":null,"num":null},{"percent":null}]}';
					$jindu_content = json_decode($jindu_content,true);
				}
                $html = $html->body(view("admin.plans.jindu_content",["CT" => $jindu_content,"ID"=>$id]));
        }
        return $html;
    }

    public function ignore_notice(Request $request)
    {
        foreach (Notice::find($request->get('ids')) as $notice) {
            $notice->status = $request->get('action');
            $notice->operatetime = date('Y-m-d H:i:s',time());
            $notice->save();
        }
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Notice::class, function (Grid $grid) {
            // $tutor_squad_ids = Squad::where('class_teacher',Admin::user()->id)->pluck('id')->toArray();
            // $test_arr = DB::table('test_assigns')->whereIn('squad_id',$tutor_squad_ids)->pluck('id')->toArray();
            // $tutor_crousesheet_ids = Crousesheet::where('tutor_id',Admin::user()->id)->pluck('id')->toArray();
            // $dictation_ids = Dictation_config::whereIn('crousesheet_id',$tutor_crousesheet_ids)->pluck('id')->toArray();
            // $grid->model()->where('starttime','<',date('Y-m-d H:i:s',time()))->whereIn('status',['1','3'])->where(function($builder) use($tutor_crousesheet_ids,$test_arr,$dictation_ids){
            //     $builder->whereIn('crousesheet_id',$tutor_crousesheet_ids)
            //         ->orWhereIn('test_assign_id',$test_arr)
            //         ->orWhereIn('dictation_config_id',$dictation_ids);
            // });
            //dd(intval(Request('squad_id')[0]));
            if (Request('squad_id')) {
                //$grid->model()->where('starttime','<',date('Y-m-d H:i:s',time()))->where('squad_id',intval(Request('squad_id')))->where('tutor_id',Admin::user()->id);
                $grid->model()->where('squad_id',Request('squad_id')[0])->where('tutor_id',Admin::user()->id);
            }else{
                //$grid->model()->where('starttime','<',date('Y-m-d H:i:s',time()))->where('tutor_id',Admin::user()->id);
                $grid->model()->where('tutor_id',Admin::user()->id);
            }

            $grid->model()->orderByRaw("FIELD(status, " . implode(", ", [3, 5,1,4,2]) . ")")->orderBy('id','desc');
            $grid->id(trans('admin.ID'))->sortable();
            $grid->column('操作')->display(function(){
                if ($this->starttime<date('Y-m-d H:i:s',time())) {
                    return '<a href="/admin/my_todo_notices/'.$this->id.'"><i class="fa fa-eye"></i></a>';
                }

            });
            $grid->notice_type(trans('admin.notice_type'))->using(['1' => '考勤', '2' => '测试', '3' => '家校', '4' => '听写','5' => '作业','6'=>'进度确认'])->sortable();
            $grid->event(trans('admin.notice_event'))->style('max-width:600px;word-break:break-all;');
            $grid->starttime(trans('admin.notice_starttime'))->sortable();
            $grid->endtime(trans('admin.notice_endtime'))->sortable();
            $grid->status(trans('admin.status'))->display(function($status){
                if ($this->status == 1) {
                    return "<span class='label bg-orange'>待完成</span>";
                }elseif ($this->status == 2) {
                    return "<span class='label bg-green'>已完成</span>";
                }
                elseif ($this->status == 3) {
                    return "<span class='label bg-red'>逾期</span>";
                }
                elseif ($this->status == 4) {
                    return "<span class='label bg-yellow'>补录完成</span>";
                }elseif ($this->status == 5) {
                    return "<span class='label bg-navy'>忽略</span>";
                }
            })->sortable();
            //$grid->operatetime(trans('admin.notice_operatetime'))->sortable();

            $grid->disableCreateButton();
            //$grid->disableFilter();
            $grid->disableExport();
            //$grid->disableRowSelector();
            $grid->disableActions();
/*            $grid->actions(function ($actions) {
                $actions->disableDelete();
                $actions->disableEdit();
            });*/
            $grid->tools(function ($tools) {
                $tools->batch(function ($batch) {
                    $batch->add('忽略', new IgnoreNotice(5));
                    $batch->disableDelete();
                });
            });

            //筛选弹出框字段
            $grid->filter(function ($filter) {
                // 去掉默认的id过滤器
                $filter->disableIdFilter();
                $filter->expand();

                $filter->in('status','状态')->multipleSelect(['1'=>'待完成','2'=>'已完成','3'=>'逾期','4'=>'补录完成','5'=>'忽略'])->default(['1','3']);
                $filter->in('notice_type','类型')->multipleSelect(['1'=>'考勤记录','2'=>'测试记录','3'=>'家校记录','4'=>'听写记录','5'=>'作业记录','6'=>'进度确认']);
                $squad_ids = Squad::where('class_teacher',Admin::user()->id)->pluck('name','id')->toArray();
                // dd($squad_ids);
                $filter->in('squad_id','班级')->multipleSelect($squad_ids);
                // $filter->scope('考勤', '考勤记录')->where('notice_type', '1');
                // $filter->scope('测试', '测试记录')->where('notice_type', '2');
                // $filter->scope('家校', '家校记录')->where('notice_type', '3');
                // $filter->scope('听写', '听写记录')->where('notice_type', '4');
                // $filter->scope('作业', '作业记录')->where('notice_type', '5');
                // $filter->scope('教学进度', '教学进度记录')->where('notice_type', '6');
            });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {

    }

    public function script()
    {
        return <<<SCRIPT

        save=function(id,type,max){
            var score = $('#'+id+'-score').val();
            if(score > max){
                toastr.error('分数已超过总分，请修改！');
                return;
            }
            $.ajax({
                method: 'PUT',
                url: '/admin/test_score_record/'+id,
                data: {
                    _token:LA.token,
                    value:score,
                    pk:id,
                    name:'test_score',
                    _editable:1
                },
                success: function () {
                    toastr.success('修改成功');
                },
                error: function () {
                    toastr.error('修改失败');
                }
            });
        }

        $(".score").on('keydown',function (e) {
                if (e.which == 13) {
                    $(this).next().click();
                }
        });

SCRIPT;
    }
}
